#include <iostream>
#include <string>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>

#define NAMEDPIPE_PATH "./MyNamedPipe"
#define NAMEDPIPE_MOD 0664

enum{
    NAMEDPIPE_CREAT_ERR = 1,
    NAMEDPIPE_CLOSE_ERR = 2,
    FILE_OPEN_READ_ERR = 3,
    FILE_OPEN_WRITE_ERR = 4
};

class Initialization{
public:
    //构造函数创建命名管道链接
    Initialization(){
        int mkfifo_ret = mkfifo(NAMEDPIPE_PATH, NAMEDPIPE_MOD);
        if(mkfifo_ret == -1){
            perror("Failed mkfifo");
            exit(NAMEDPIPE_CREAT_ERR);
        }
    }

    //析构函数关闭管道
    ~Initialization(){
        int unlink_ret = unlink(NAMEDPIPE_PATH);
        if(unlink_ret == -1){
            perror("Failed unlink");
            exit(NAMEDPIPE_CLOSE_ERR);
        }
    }
};